﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Announcement.Model;

namespace Announcement.Admin 
{
    public partial class GarageEdit : AdminLoginPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //取得表单数据
                GarageTable gt = new GarageTable();
                gt.DistrictName = ((Label)fvGarage.FindControl("DistrictNameLabel")).Text;
                gt.DevelopersName = ((Label)fvGarage.FindControl("DevelopersNameLabel")).Text;
                gt.StartDate = DateTime.Parse(((Label)fvGarage.FindControl("StartDateLabel")).Text);
                gt.EndDate = DateTime.Parse(((Label)fvGarage.FindControl("EndDateLabel")).Text);
                gt.FillDate = DateTime.Parse(((Label)fvGarage.FindControl("FillDateLabel")).Text);
                gt.HouseSoldRate = Decimal.Parse(((Label)fvGarage.FindControl("HouseSoldRateLabel")).Text);
                gt.GarageSold = Convert.ToInt32(((Label)fvGarage.FindControl("GarageSoldLabel")).Text);
                gt.GarageUnsold = Convert.ToInt32(((Label)fvGarage.FindControl("GarageUnsoldLabel")).Text);

                Session["GarageTable"] = gt;
            }

        }

        protected void fvGarage_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            if (e.CommandName == "Back")
            {
                string id = Request.QueryString["Id"];
                string mode = Request.QueryString["mode"];
                Response.Redirect("~/Admin/ApplyEdit.aspx?Id=" + id + "&mode=" + mode);
            }
            if (e.CommandName == "Sales")
            {
                HiddenField hfId = (HiddenField)fvGarage.FindControl("hfId");
                string gId = hfId.Value;
                string cCode = Request.QueryString["CCode"];
                string id = Request.QueryString["Id"];
                string mode = Request.QueryString["mode"];
                Response.Redirect("~/Admin/SalesEdit.aspx?GarageId=" + gId + "&CCode=" + cCode + "&Id=" + id + "&mode=" + mode);
            }
            if (e.CommandName == "Announcement")
            {
                Response.Redirect("~/Sell.aspx?isPrn=true");
            }
        }

        protected void lbtnExit_Click(object sender, EventArgs e)
        {
            Session["AdminUserName"] = null;
            Response.Redirect("../Login.aspx");
        }
    }
}
